In [1]:
import warnings
warnings.filterwarnings('ignore')

#importing the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from word2number import w2n
from tqdm import tqdm
In [2]:
!pip install word2number
Requirement already satisfied: word2number in c:\users\ghoshs\appdata\local\continuum\anaconda3\lib\site-packages (1.1)
In [3]:
cars = pd.read_csv('CarPrice_Assignment.csv')
In [4]:
cars.head(2)
Out[4]:
car_ID symboling CarName fueltype aspiration doornumber carbody drivewheel enginelocation wheelbase ... enginesize fuelsystem boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price
0 1 3 alfa-romero giulia gas std two convertible rwd front 88.6 ... 130 mpfi 3.47 2.68 9.0 111 5000 21 27 13495.0
1 2 3 alfa-romero stelvio gas std two convertible rwd front 88.6 ... 130 mpfi 3.47 2.68 9.0 111 5000 21 27 16500.0

2 rows × 26 columns

In [5]:
cars.tail()
Out[5]:
car_ID symboling CarName fueltype aspiration doornumber carbody drivewheel enginelocation wheelbase ... enginesize fuelsystem boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price
200 201 -1 volvo 145e (sw) gas std four sedan rwd front 109.1 ... 141 mpfi 3.78 3.15 9.5 114 5400 23 28 16845.0
201 202 -1 volvo 144ea gas turbo four sedan rwd front 109.1 ... 141 mpfi 3.78 3.15 8.7 160 5300 19 25 19045.0
202 203 -1 volvo 244dl gas std four sedan rwd front 109.1 ... 173 mpfi 3.58 2.87 8.8 134 5500 18 23 21485.0
203 204 -1 volvo 246 diesel turbo four sedan rwd front 109.1 ... 145 idi 3.01 3.40 23.0 106 4800 26 27 22470.0
204 205 -1 volvo 264gl gas turbo four sedan rwd front 109.1 ... 141 mpfi 3.78 3.15 9.5 114 5400 19 25 22625.0

5 rows × 26 columns

In [6]:
cars.shape
Out[6]:
(205, 26)
In [7]:
cars.describe()
Out[7]:
car_ID symboling wheelbase carlength carwidth carheight curbweight enginesize boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price
count 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000 205.000000
mean 103.000000 0.834146 98.756585 174.049268 65.907805 53.724878 2555.565854 126.907317 3.329756 3.255415 10.142537 104.117073 5125.121951 25.219512 30.751220 13276.710571
std 59.322565 1.245307 6.021776 12.337289 2.145204 2.443522 520.680204 41.642693 0.270844 0.313597 3.972040 39.544167 476.985643 6.542142 6.886443 7988.852332
min 1.000000 -2.000000 86.600000 141.100000 60.300000 47.800000 1488.000000 61.000000 2.540000 2.070000 7.000000 48.000000 4150.000000 13.000000 16.000000 5118.000000
25% 52.000000 0.000000 94.500000 166.300000 64.100000 52.000000 2145.000000 97.000000 3.150000 3.110000 8.600000 70.000000 4800.000000 19.000000 25.000000 7788.000000
50% 103.000000 1.000000 97.000000 173.200000 65.500000 54.100000 2414.000000 120.000000 3.310000 3.290000 9.000000 95.000000 5200.000000 24.000000 30.000000 10295.000000
75% 154.000000 2.000000 102.400000 183.100000 66.900000 55.500000 2935.000000 141.000000 3.580000 3.410000 9.400000 116.000000 5500.000000 30.000000 34.000000 16503.000000
max 205.000000 3.000000 120.900000 208.100000 72.300000 59.800000 4066.000000 326.000000 3.940000 4.170000 23.000000 288.000000 6600.000000 49.000000 54.000000 45400.000000
In [8]:
cars.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 205 entries, 0 to 204
Data columns (total 26 columns):
 #   Column            Non-Null Count  Dtype  
---  ------            --------------  -----  
 0   car_ID            205 non-null    int64  
 1   symboling         205 non-null    int64  
 2   CarName           205 non-null    object 
 3   fueltype          194 non-null    object 
 4   aspiration        205 non-null    object 
 5   doornumber        205 non-null    object 
 6   carbody           200 non-null    object 
 7   drivewheel        205 non-null    object 
 8   enginelocation    193 non-null    object 
 9   wheelbase         205 non-null    float64
 10  carlength         205 non-null    float64
 11  carwidth          205 non-null    float64
 12  carheight         205 non-null    float64
 13  curbweight        205 non-null    int64  
 14  enginetype        205 non-null    object 
 15  cylindernumber    205 non-null    object 
 16  enginesize        205 non-null    int64  
 17  fuelsystem        205 non-null    object 
 18  boreratio         205 non-null    float64
 19  stroke            205 non-null    float64
 20  compressionratio  205 non-null    float64
 21  horsepower        205 non-null    int64  
 22  peakrpm           205 non-null    int64  
 23  citympg           205 non-null    int64  
 24  highwaympg        205 non-null    int64  
 25  price             205 non-null    float64
dtypes: float64(8), int64(8), object(10)
memory usage: 41.8+ KB
In [9]:
cars.columns
Out[9]:
Index(['car_ID', 'symboling', 'CarName', 'fueltype', 'aspiration',
       'doornumber', 'carbody', 'drivewheel', 'enginelocation', 'wheelbase',
       'carlength', 'carwidth', 'carheight', 'curbweight', 'enginetype',
       'cylindernumber', 'enginesize', 'fuelsystem', 'boreratio', 'stroke',
       'compressionratio', 'horsepower', 'peakrpm', 'citympg', 'highwaympg',
       'price'],
      dtype='object')
In [10]:
list(cars.columns)
Out[10]:
['car_ID',
 'symboling',
 'CarName',
 'fueltype',
 'aspiration',
 'doornumber',
 'carbody',
 'drivewheel',
 'enginelocation',
 'wheelbase',
 'carlength',
 'carwidth',
 'carheight',
 'curbweight',
 'enginetype',
 'cylindernumber',
 'enginesize',
 'fuelsystem',
 'boreratio',
 'stroke',
 'compressionratio',
 'horsepower',
 'peakrpm',
 'citympg',
 'highwaympg',
 'price']
In [11]:
for x in cars.columns:
    print(x)
car_ID
symboling
CarName
fueltype
aspiration
doornumber
carbody
drivewheel
enginelocation
wheelbase
carlength
carwidth
carheight
curbweight
enginetype
cylindernumber
enginesize
fuelsystem
boreratio
stroke
compressionratio
horsepower
peakrpm
citympg
highwaympg
price
In [12]:
cars.describe().T
Out[12]:
count mean std min 25% 50% 75% max
car_ID 205.0 103.000000 59.322565 1.00 52.00 103.00 154.00 205.00
symboling 205.0 0.834146 1.245307 -2.00 0.00 1.00 2.00 3.00
wheelbase 205.0 98.756585 6.021776 86.60 94.50 97.00 102.40 120.90
carlength 205.0 174.049268 12.337289 141.10 166.30 173.20 183.10 208.10
carwidth 205.0 65.907805 2.145204 60.30 64.10 65.50 66.90 72.30
carheight 205.0 53.724878 2.443522 47.80 52.00 54.10 55.50 59.80
curbweight 205.0 2555.565854 520.680204 1488.00 2145.00 2414.00 2935.00 4066.00
enginesize 205.0 126.907317 41.642693 61.00 97.00 120.00 141.00 326.00
boreratio 205.0 3.329756 0.270844 2.54 3.15 3.31 3.58 3.94
stroke 205.0 3.255415 0.313597 2.07 3.11 3.29 3.41 4.17
compressionratio 205.0 10.142537 3.972040 7.00 8.60 9.00 9.40 23.00
horsepower 205.0 104.117073 39.544167 48.00 70.00 95.00 116.00 288.00
peakrpm 205.0 5125.121951 476.985643 4150.00 4800.00 5200.00 5500.00 6600.00
citympg 205.0 25.219512 6.542142 13.00 19.00 24.00 30.00 49.00
highwaympg 205.0 30.751220 6.886443 16.00 25.00 30.00 34.00 54.00
price 205.0 13276.710571 7988.852332 5118.00 7788.00 10295.00 16503.00 45400.00
In [13]:
cars.describe(include='object').T
Out[13]:
count unique top freq
CarName 205 147 toyota corona 6
fueltype 194 2 gas 174
aspiration 205 2 std 168
doornumber 205 2 four 115
carbody 200 5 sedan 91
drivewheel 205 3 fwd 120
enginelocation 193 2 front 190
enginetype 205 7 ohc 148
cylindernumber 205 7 four 159
fuelsystem 205 8 mpfi 94
In [14]:
list(cars.columns[cars.dtypes == 'int64'])
Out[14]:
['car_ID',
 'symboling',
 'curbweight',
 'enginesize',
 'horsepower',
 'peakrpm',
 'citympg',
 'highwaympg']
In [15]:
cars.iloc[0:5, 0:4]
Out[15]:
car_ID symboling CarName fueltype
0 1 3 alfa-romero giulia gas
1 2 3 alfa-romero stelvio gas
2 3 1 alfa-romero Quadrifoglio gas
3 4 2 audi 100 ls gas
4 5 2 audi 100ls gas
In [16]:
cars.loc[0:5,['CarName','fueltype']]
Out[16]:
CarName fueltype
0 alfa-romero giulia gas
1 alfa-romero stelvio gas
2 alfa-romero Quadrifoglio gas
3 audi 100 ls gas
4 audi 100ls gas
5 audi fox gas
In [17]:
cars['fueltype'].unique()
Out[17]:
array(['gas', nan, 'diesel'], dtype=object)
In [18]:
cars['fueltype'].dtype
Out[18]:
dtype('O')
In [19]:
cars['fueltype'].value_counts()
Out[19]:
gas       174
diesel     20
Name: fueltype, dtype: int64
In [20]:
cars.isnull().sum()
Out[20]:
car_ID               0
symboling            0
CarName              0
fueltype            11
aspiration           0
doornumber           0
carbody              5
drivewheel           0
enginelocation      12
wheelbase            0
carlength            0
carwidth             0
carheight            0
curbweight           0
enginetype           0
cylindernumber       0
enginesize           0
fuelsystem           0
boreratio            0
stroke               0
compressionratio     0
horsepower           0
peakrpm              0
citympg              0
highwaympg           0
price                0
dtype: int64
In [21]:
cars.isnull().any()
Out[21]:
car_ID              False
symboling           False
CarName             False
fueltype             True
aspiration          False
doornumber          False
carbody              True
drivewheel          False
enginelocation       True
wheelbase           False
carlength           False
carwidth            False
carheight           False
curbweight          False
enginetype          False
cylindernumber      False
enginesize          False
fuelsystem          False
boreratio           False
stroke              False
compressionratio    False
horsepower          False
peakrpm             False
citympg             False
highwaympg          False
price               False
dtype: bool
In [22]:
cars_copy = cars.copy()
In [23]:
null_columns=cars.columns[cars.isnull().any()]
cars[null_columns].isnull().sum()*100/len(cars)
Out[23]:
fueltype          5.365854
carbody           2.439024
enginelocation    5.853659
dtype: float64
In [24]:
list(null_columns)
Out[24]:
['fueltype', 'carbody', 'enginelocation']
In [25]:
for x in cars.columns[cars.isnull().any()]:
    print('--------------------------------')
    print('Column Name:',x)
    print('--------------------------------')
    print(cars[x].value_counts()*100/len(cars))
    print(cars[x].value_counts())
--------------------------------
Column Name: fueltype
--------------------------------
gas       84.878049
diesel     9.756098
Name: fueltype, dtype: float64
gas       174
diesel     20
Name: fueltype, dtype: int64
--------------------------------
Column Name: carbody
--------------------------------
sedan          44.390244
hatchback      34.146341
wagon          12.195122
hardtop         3.902439
convertible     2.926829
Name: carbody, dtype: float64
sedan          91
hatchback      70
wagon          25
hardtop         8
convertible     6
Name: carbody, dtype: int64
--------------------------------
Column Name: enginelocation
--------------------------------
front    92.682927
rear      1.463415
Name: enginelocation, dtype: float64
front    190
rear       3
Name: enginelocation, dtype: int64
In [26]:
cars['fueltype'].fillna (value='gas', inplace = True)
cars['enginelocation'].fillna (value='front', inplace = True)
In [27]:
cars['fueltype'].unique()
Out[27]:
array(['gas', 'diesel'], dtype=object)
In [28]:
cars['enginelocation'].unique()
Out[28]:
array(['front', 'rear'], dtype=object)
In [29]:
for x in cars.columns:
    print('--------------------------------')
    print('Column Name:',x)
    print('--------------------------------')
    print(cars[x].value_counts()*100/len(cars))
    print(cars[x].value_counts())
--------------------------------
Column Name: car_ID
--------------------------------
1      0.487805
142    0.487805
132    0.487805
133    0.487805
134    0.487805
         ...   
72     0.487805
73     0.487805
74     0.487805
75     0.487805
205    0.487805
Name: car_ID, Length: 205, dtype: float64
1      1
142    1
132    1
133    1
134    1
      ..
72     1
73     1
74     1
75     1
205    1
Name: car_ID, Length: 205, dtype: int64
--------------------------------
Column Name: symboling
--------------------------------
 0    32.682927
 1    26.341463
 2    15.609756
 3    13.170732
-1    10.731707
-2     1.463415
Name: symboling, dtype: float64
 0    67
 1    54
 2    32
 3    27
-1    22
-2     3
Name: symboling, dtype: int64
--------------------------------
Column Name: CarName
--------------------------------
toyota corona           2.926829
toyota corolla          2.926829
peugeot 504             2.926829
subaru dl               1.951220
mitsubishi mirage g4    1.463415
                          ...   
mazda glc 4             0.487805
mazda rx2 coupe         0.487805
maxda glc deluxe        0.487805
maxda rx3               0.487805
volvo 246               0.487805
Name: CarName, Length: 147, dtype: float64
toyota corona           6
toyota corolla          6
peugeot 504             6
subaru dl               4
mitsubishi mirage g4    3
                       ..
mazda glc 4             1
mazda rx2 coupe         1
maxda glc deluxe        1
maxda rx3               1
volvo 246               1
Name: CarName, Length: 147, dtype: int64
--------------------------------
Column Name: fueltype
--------------------------------
gas       90.243902
diesel     9.756098
Name: fueltype, dtype: float64
gas       185
diesel     20
Name: fueltype, dtype: int64
--------------------------------
Column Name: aspiration
--------------------------------
std      81.95122
turbo    18.04878
Name: aspiration, dtype: float64
std      168
turbo     37
Name: aspiration, dtype: int64
--------------------------------
Column Name: doornumber
--------------------------------
four    56.097561
two     43.902439
Name: doornumber, dtype: float64
four    115
two      90
Name: doornumber, dtype: int64
--------------------------------
Column Name: carbody
--------------------------------
sedan          44.390244
hatchback      34.146341
wagon          12.195122
hardtop         3.902439
convertible     2.926829
Name: carbody, dtype: float64
sedan          91
hatchback      70
wagon          25
hardtop         8
convertible     6
Name: carbody, dtype: int64
--------------------------------
Column Name: drivewheel
--------------------------------
fwd    58.536585
rwd    37.073171
4wd     4.390244
Name: drivewheel, dtype: float64
fwd    120
rwd     76
4wd      9
Name: drivewheel, dtype: int64
--------------------------------
Column Name: enginelocation
--------------------------------
front    98.536585
rear      1.463415
Name: enginelocation, dtype: float64
front    202
rear       3
Name: enginelocation, dtype: int64
--------------------------------
Column Name: wheelbase
--------------------------------
94.5     10.243902
93.7      9.756098
95.7      6.341463
96.5      3.902439
97.3      3.414634
98.4      3.414634
104.3     2.926829
100.4     2.926829
107.9     2.926829
98.8      2.926829
99.1      2.926829
96.3      2.926829
109.1     2.439024
93.1      2.439024
97.2      2.439024
95.9      2.439024
102.4     2.439024
97.0      1.951220
95.3      1.951220
114.2     1.951220
101.2     1.951220
110.0     1.463415
103.5     1.463415
89.5      1.463415
105.8     1.463415
96.1      0.975610
102.9     0.975610
104.5     0.975610
91.3      0.975610
96.9      0.975610
88.6      0.975610
113.0     0.975610
99.8      0.975610
115.6     0.975610
103.3     0.975610
86.6      0.975610
104.9     0.975610
93.3      0.487805
99.4      0.487805
99.5      0.487805
88.4      0.487805
94.3      0.487805
96.0      0.487805
95.1      0.487805
93.0      0.487805
102.0     0.487805
106.7     0.487805
108.0     0.487805
96.6      0.487805
99.2      0.487805
112.0     0.487805
102.7     0.487805
120.9     0.487805
Name: wheelbase, dtype: float64
94.5     21
93.7     20
95.7     13
96.5      8
97.3      7
98.4      7
104.3     6
100.4     6
107.9     6
98.8      6
99.1      6
96.3      6
109.1     5
93.1      5
97.2      5
95.9      5
102.4     5
97.0      4
95.3      4
114.2     4
101.2     4
110.0     3
103.5     3
89.5      3
105.8     3
96.1      2
102.9     2
104.5     2
91.3      2
96.9      2
88.6      2
113.0     2
99.8      2
115.6     2
103.3     2
86.6      2
104.9     2
93.3      1
99.4      1
99.5      1
88.4      1
94.3      1
96.0      1
95.1      1
93.0      1
102.0     1
106.7     1
108.0     1
96.6      1
99.2      1
112.0     1
102.7     1
120.9     1
Name: wheelbase, dtype: int64
--------------------------------
Column Name: carlength
--------------------------------
157.3    7.317073
188.8    5.365854
171.7    3.414634
186.7    3.414634
166.3    3.414634
           ...   
165.6    0.487805
187.5    0.487805
180.3    0.487805
208.1    0.487805
199.2    0.487805
Name: carlength, Length: 75, dtype: float64
157.3    15
188.8    11
171.7     7
186.7     7
166.3     7
         ..
165.6     1
187.5     1
180.3     1
208.1     1
199.2     1
Name: carlength, Length: 75, dtype: int64
--------------------------------
Column Name: carwidth
--------------------------------
63.8    11.707317
66.5    11.219512
65.4     7.317073
63.6     5.365854
64.4     4.878049
68.4     4.878049
64.0     4.390244
65.5     3.902439
65.2     3.414634
64.2     2.926829
66.3     2.926829
65.6     2.926829
67.2     2.926829
67.9     2.439024
66.9     2.439024
65.7     1.951220
68.9     1.951220
64.8     1.951220
63.9     1.463415
70.3     1.463415
71.7     1.463415
71.4     1.463415
65.0     1.463415
68.3     0.975610
67.7     0.975610
64.1     0.975610
66.1     0.975610
69.6     0.975610
64.6     0.975610
72.0     0.487805
68.0     0.487805
70.5     0.487805
61.8     0.487805
66.0     0.487805
62.5     0.487805
70.6     0.487805
72.3     0.487805
66.6     0.487805
63.4     0.487805
60.3     0.487805
70.9     0.487805
66.4     0.487805
66.2     0.487805
68.8     0.487805
Name: carwidth, dtype: float64
63.8    24
66.5    23
65.4    15
63.6    11
64.4    10
68.4    10
64.0     9
65.5     8
65.2     7
64.2     6
66.3     6
65.6     6
67.2     6
67.9     5
66.9     5
65.7     4
68.9     4
64.8     4
63.9     3
70.3     3
71.7     3
71.4     3
65.0     3
68.3     2
67.7     2
64.1     2
66.1     2
69.6     2
64.6     2
72.0     1
68.0     1
70.5     1
61.8     1
66.0     1
62.5     1
70.6     1
72.3     1
66.6     1
63.4     1
60.3     1
70.9     1
66.4     1
66.2     1
68.8     1
Name: carwidth, dtype: int64
--------------------------------
Column Name: carheight
--------------------------------
50.8    6.829268
52.0    5.853659
55.7    5.853659
54.1    4.878049
54.5    4.878049
55.5    4.390244
56.7    3.902439
54.3    3.902439
52.6    3.414634
56.1    3.414634
51.6    3.414634
53.0    2.926829
52.8    2.926829
54.9    2.926829
50.2    2.926829
53.7    2.439024
55.1    2.439024
50.6    2.439024
49.6    1.951220
58.7    1.951220
53.3    1.951220
52.5    1.463415
59.1    1.463415
56.2    1.463415
49.7    1.463415
57.5    1.463415
53.5    1.463415
54.4    0.975610
53.9    0.975610
56.3    0.975610
50.5    0.975610
59.8    0.975610
56.5    0.975610
54.7    0.975610
48.8    0.975610
49.4    0.975610
51.4    0.975610
51.0    0.487805
54.8    0.487805
55.4    0.487805
56.0    0.487805
55.2    0.487805
53.2    0.487805
47.8    0.487805
55.9    0.487805
52.4    0.487805
55.6    0.487805
53.1    0.487805
58.3    0.487805
Name: carheight, dtype: float64
50.8    14
52.0    12
55.7    12
54.1    10
54.5    10
55.5     9
56.7     8
54.3     8
52.6     7
56.1     7
51.6     7
53.0     6
52.8     6
54.9     6
50.2     6
53.7     5
55.1     5
50.6     5
49.6     4
58.7     4
53.3     4
52.5     3
59.1     3
56.2     3
49.7     3
57.5     3
53.5     3
54.4     2
53.9     2
56.3     2
50.5     2
59.8     2
56.5     2
54.7     2
48.8     2
49.4     2
51.4     2
51.0     1
54.8     1
55.4     1
56.0     1
55.2     1
53.2     1
47.8     1
55.9     1
52.4     1
55.6     1
53.1     1
58.3     1
Name: carheight, dtype: int64
--------------------------------
Column Name: curbweight
--------------------------------
2385    1.951220
1918    1.463415
2275    1.463415
1989    1.463415
2410    0.975610
          ...   
2370    0.487805
2328    0.487805
2833    0.487805
2921    0.487805
3062    0.487805
Name: curbweight, Length: 171, dtype: float64
2385    4
1918    3
2275    3
1989    3
2410    2
       ..
2370    1
2328    1
2833    1
2921    1
3062    1
Name: curbweight, Length: 171, dtype: int64
--------------------------------
Column Name: enginetype
--------------------------------
ohc      72.195122
ohcf      7.317073
ohcv      6.341463
dohc      5.853659
l         5.853659
rotor     1.951220
dohcv     0.487805
Name: enginetype, dtype: float64
ohc      148
ohcf      15
ohcv      13
dohc      12
l         12
rotor      4
dohcv      1
Name: enginetype, dtype: int64
--------------------------------
Column Name: cylindernumber
--------------------------------
four      77.560976
six       11.707317
five       5.365854
eight      2.439024
two        1.951220
three      0.487805
twelve     0.487805
Name: cylindernumber, dtype: float64
four      159
six        24
five       11
eight       5
two         4
three       1
twelve      1
Name: cylindernumber, dtype: int64
--------------------------------
Column Name: enginesize
--------------------------------
122    7.317073
92     7.317073
97     6.829268
98     6.829268
108    6.341463
90     5.853659
110    5.853659
109    3.902439
120    3.414634
141    3.414634
152    2.926829
181    2.926829
146    2.926829
121    2.926829
156    2.439024
136    2.439024
91     2.439024
183    1.951220
130    1.951220
171    1.463415
70     1.463415
194    1.463415
209    1.463415
164    1.463415
258    0.975610
140    0.975610
134    0.975610
234    0.975610
132    0.975610
131    0.975610
173    0.487805
203    0.487805
161    0.487805
80     0.487805
151    0.487805
103    0.487805
304    0.487805
308    0.487805
326    0.487805
119    0.487805
111    0.487805
79     0.487805
61     0.487805
145    0.487805
Name: enginesize, dtype: float64
122    15
92     15
97     14
98     14
108    13
90     12
110    12
109     8
120     7
141     7
152     6
181     6
146     6
121     6
156     5
136     5
91      5
183     4
130     4
171     3
70      3
194     3
209     3
164     3
258     2
140     2
134     2
234     2
132     2
131     2
173     1
203     1
161     1
80      1
151     1
103     1
304     1
308     1
326     1
119     1
111     1
79      1
61      1
145     1
Name: enginesize, dtype: int64
--------------------------------
Column Name: fuelsystem
--------------------------------
mpfi    45.853659
2bbl    32.195122
idi      9.756098
1bbl     5.365854
spdi     4.390244
4bbl     1.463415
mfi      0.487805
spfi     0.487805
Name: fuelsystem, dtype: float64
mpfi    94
2bbl    66
idi     20
1bbl    11
spdi     9
4bbl     3
mfi      1
spfi     1
Name: fuelsystem, dtype: int64
--------------------------------
Column Name: boreratio
--------------------------------
3.62    11.219512
3.19     9.756098
3.15     7.317073
3.03     5.853659
2.97     5.853659
3.46     4.390244
3.31     3.902439
3.43     3.902439
3.78     3.902439
3.27     3.414634
2.91     3.414634
3.58     2.926829
3.39     2.926829
3.33     2.926829
3.05     2.926829
3.54     2.926829
3.70     2.439024
3.01     2.439024
3.35     1.951220
3.17     1.463415
3.59     1.463415
3.74     1.463415
3.47     0.975610
3.94     0.975610
3.24     0.975610
3.63     0.975610
3.13     0.975610
3.80     0.975610
3.50     0.975610
2.54     0.487805
3.08     0.487805
3.61     0.487805
3.34     0.487805
2.68     0.487805
3.60     0.487805
2.92     0.487805
3.76     0.487805
2.99     0.487805
Name: boreratio, dtype: float64
3.62    23
3.19    20
3.15    15
3.03    12
2.97    12
3.46     9
3.31     8
3.43     8
3.78     8
3.27     7
2.91     7
3.58     6
3.39     6
3.33     6
3.05     6
3.54     6
3.70     5
3.01     5
3.35     4
3.17     3
3.59     3
3.74     3
3.47     2
3.94     2
3.24     2
3.63     2
3.13     2
3.80     2
3.50     2
2.54     1
3.08     1
3.61     1
3.34     1
2.68     1
3.60     1
2.92     1
3.76     1
2.99     1
Name: boreratio, dtype: int64
--------------------------------
Column Name: stroke
--------------------------------
3.400    9.756098
3.230    6.829268
3.150    6.829268
3.030    6.829268
3.390    6.341463
2.640    5.365854
3.290    4.390244
3.350    4.390244
3.460    3.902439
3.110    2.926829
3.270    2.926829
3.410    2.926829
3.070    2.926829
3.580    2.926829
3.190    2.926829
3.500    2.926829
3.640    2.439024
3.520    2.439024
3.860    1.951220
3.540    1.951220
3.470    1.951220
3.255    1.951220
3.900    1.463415
2.900    1.463415
3.100    0.975610
4.170    0.975610
2.800    0.975610
2.190    0.975610
3.080    0.975610
2.680    0.975610
2.360    0.487805
3.160    0.487805
2.070    0.487805
3.210    0.487805
3.120    0.487805
2.760    0.487805
2.870    0.487805
Name: stroke, dtype: float64
3.400    20
3.230    14
3.150    14
3.030    14
3.390    13
2.640    11
3.290     9
3.350     9
3.460     8
3.110     6
3.270     6
3.410     6
3.070     6
3.580     6
3.190     6
3.500     6
3.640     5
3.520     5
3.860     4
3.540     4
3.470     4
3.255     4
3.900     3
2.900     3
3.100     2
4.170     2
2.800     2
2.190     2
3.080     2
2.680     2
2.360     1
3.160     1
2.070     1
3.210     1
3.120     1
2.760     1
2.870     1
Name: stroke, dtype: int64
--------------------------------
Column Name: compressionratio
--------------------------------
9.00     22.439024
9.40     12.682927
8.50      6.829268
9.50      6.341463
9.30      5.365854
8.70      4.390244
8.00      3.902439
9.20      3.902439
7.00      3.414634
8.60      2.439024
21.00     2.439024
8.40      2.439024
7.50      2.439024
23.00     2.439024
9.60      2.439024
21.50     1.951220
7.60      1.951220
10.00     1.463415
22.50     1.463415
8.30      1.463415
8.80      1.463415
7.70      0.975610
8.10      0.975610
9.10      0.487805
9.31      0.487805
7.80      0.487805
9.41      0.487805
21.90     0.487805
22.00     0.487805
22.70     0.487805
10.10     0.487805
11.50     0.487805
Name: compressionratio, dtype: float64
9.00     46
9.40     26
8.50     14
9.50     13
9.30     11
8.70      9
8.00      8
9.20      8
7.00      7
8.60      5
21.00     5
8.40      5
7.50      5
23.00     5
9.60      5
21.50     4
7.60      4
10.00     3
22.50     3
8.30      3
8.80      3
7.70      2
8.10      2
9.10      1
9.31      1
7.80      1
9.41      1
21.90     1
22.00     1
22.70     1
10.10     1
11.50     1
Name: compressionratio, dtype: int64
--------------------------------
Column Name: horsepower
--------------------------------
68     9.268293
70     5.365854
69     4.878049
116    4.390244
110    3.902439
95     3.414634
114    2.926829
160    2.926829
101    2.926829
62     2.926829
88     2.926829
145    2.439024
76     2.439024
97     2.439024
84     2.439024
90     2.439024
82     2.439024
102    2.439024
92     1.951220
111    1.951220
123    1.951220
86     1.951220
207    1.463415
73     1.463415
182    1.463415
121    1.463415
85     1.463415
152    1.463415
176    0.975610
94     0.975610
56     0.975610
112    0.975610
161    0.975610
184    0.975610
155    0.975610
156    0.975610
52     0.975610
100    0.975610
162    0.975610
140    0.487805
115    0.487805
134    0.487805
78     0.487805
142    0.487805
288    0.487805
143    0.487805
48     0.487805
200    0.487805
58     0.487805
55     0.487805
60     0.487805
175    0.487805
154    0.487805
72     0.487805
120    0.487805
64     0.487805
135    0.487805
262    0.487805
106    0.487805
Name: horsepower, dtype: float64
68     19
70     11
69     10
116     9
110     8
95      7
114     6
160     6
101     6
62      6
88      6
145     5
76      5
97      5
84      5
90      5
82      5
102     5
92      4
111     4
123     4
86      4
207     3
73      3
182     3
121     3
85      3
152     3
176     2
94      2
56      2
112     2
161     2
184     2
155     2
156     2
52      2
100     2
162     2
140     1
115     1
134     1
78      1
142     1
288     1
143     1
48      1
200     1
58      1
55      1
60      1
175     1
154     1
72      1
120     1
64      1
135     1
262     1
106     1
Name: horsepower, dtype: int64
--------------------------------
Column Name: peakrpm
--------------------------------
5500    18.048780
4800    17.560976
5000    13.170732
5200    11.219512
5400     6.341463
6000     4.390244
4500     3.414634
5800     3.414634
5250     3.414634
5100     2.439024
4150     2.439024
4200     2.439024
4350     1.951220
4750     1.951220
5900     1.463415
4250     1.463415
4400     1.463415
6600     0.975610
4650     0.487805
5600     0.487805
5750     0.487805
4900     0.487805
5300     0.487805
Name: peakrpm, dtype: float64
5500    37
4800    36
5000    27
5200    23
5400    13
6000     9
4500     7
5800     7
5250     7
5100     5
4150     5
4200     5
4350     4
4750     4
5900     3
4250     3
4400     3
6600     2
4650     1
5600     1
5750     1
4900     1
5300     1
Name: peakrpm, dtype: int64
--------------------------------
Column Name: citympg
--------------------------------
31    13.658537
19    13.170732
24    10.731707
27     6.829268
17     6.341463
26     5.853659
23     5.853659
21     3.902439
25     3.902439
30     3.902439
38     3.414634
28     3.414634
16     2.926829
37     2.926829
22     1.951220
29     1.463415
15     1.463415
20     1.463415
18     1.463415
14     0.975610
34     0.487805
35     0.487805
32     0.487805
36     0.487805
45     0.487805
13     0.487805
49     0.487805
47     0.487805
33     0.487805
Name: citympg, dtype: float64
31    28
19    27
24    22
27    14
17    13
26    12
23    12
21     8
25     8
30     8
38     7
28     7
16     6
37     6
22     4
29     3
15     3
20     3
18     3
14     2
34     1
35     1
32     1
36     1
45     1
13     1
49     1
47     1
33     1
Name: citympg, dtype: int64
--------------------------------
Column Name: highwaympg
--------------------------------
25    9.268293
38    8.292683
24    8.292683
30    7.804878
32    7.804878
34    6.829268
37    6.341463
28    6.341463
29    4.878049
33    4.390244
22    3.902439
31    3.902439
23    3.414634
27    2.439024
43    1.951220
42    1.463415
26    1.463415
41    1.463415
19    0.975610
39    0.975610
18    0.975610
16    0.975610
20    0.975610
36    0.975610
47    0.975610
46    0.975610
54    0.487805
17    0.487805
53    0.487805
50    0.487805
Name: highwaympg, dtype: float64
25    19
38    17
24    17
30    16
32    16
34    14
37    13
28    13
29    10
33     9
22     8
31     8
23     7
27     5
43     4
42     3
26     3
41     3
19     2
39     2
18     2
16     2
20     2
36     2
47     2
46     2
54     1
17     1
53     1
50     1
Name: highwaympg, dtype: int64
--------------------------------
Column Name: price
--------------------------------
8921.0     0.975610
9279.0     0.975610
7898.0     0.975610
8916.5     0.975610
7775.0     0.975610
             ...   
45400.0    0.487805
16503.0    0.487805
5389.0     0.487805
6189.0     0.487805
22625.0    0.487805
Name: price, Length: 189, dtype: float64
8921.0     2
9279.0     2
7898.0     2
8916.5     2
7775.0     2
          ..
45400.0    1
16503.0    1
5389.0     1
6189.0     1
22625.0    1
Name: price, Length: 189, dtype: int64
In [30]:
cars.loc[cars['carbody'].isnull()]
Out[30]:
car_ID symboling CarName fueltype aspiration doornumber carbody drivewheel enginelocation wheelbase ... enginesize fuelsystem boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price
3 4 2 audi 100 ls gas std four NaN fwd front 99.8 ... 109 mpfi 3.19 3.40 10.0 102 5500 24 30 13950.0
4 5 2 audi 100ls gas std four NaN 4wd front 99.4 ... 136 mpfi 3.19 3.40 8.0 115 5500 18 22 17450.0
13 14 0 bmw x3 gas std four NaN rwd front 101.2 ... 164 mpfi 3.31 3.19 9.0 121 4250 21 28 21105.0
14 15 1 bmw z4 gas std four NaN rwd front 103.5 ... 164 mpfi 3.31 3.19 9.0 121 4250 20 25 24565.0
41 42 0 honda civic gas std four NaN fwd front 96.5 ... 110 mpfi 3.15 3.58 9.0 101 5800 24 28 12945.0

5 rows × 26 columns

In [31]:
cars['carbody'] = np.where(
   (cars['CarName'] =='audi 100 ls') & (cars['carbody'].isnull()) , 'sedan', cars['carbody'])
In [32]:
cars['carbody'] = np.where(
   (cars['CarName'] =='audi 100ls') & (cars['carbody'].isnull()) , 'sedan', cars['carbody'])
In [33]:
cars['carbody'].fillna (value='sedan', inplace = True)
In [34]:
pd.set_option('display.max_rows',20000, 'display.max_columns',100)
In [35]:
cars['CarName'].value_counts().sort_index(ascending=True)
Out[35]:
Nissan versa                       1
alfa-romero Quadrifoglio           1
alfa-romero giulia                 1
alfa-romero stelvio                1
audi 100 ls                        1
audi 100ls                         2
audi 4000                          1
audi 5000                          1
audi 5000s (diesel)                1
audi fox                           1
bmw 320i                           2
bmw x1                             1
bmw x3                             2
bmw x4                             1
bmw x5                             1
bmw z4                             1
buick century                      1
buick century luxus (sw)           1
buick century special              1
buick electra 225 custom           1
buick opel isuzu deluxe            1
buick regal sport coupe (turbo)    1
buick skyhawk                      1
buick skylark                      1
chevrolet impala                   1
chevrolet monte carlo              1
chevrolet vega 2300                1
dodge challenger se                1
dodge colt (sw)                    1
dodge colt hardtop                 1
dodge coronet custom               1
dodge coronet custom (sw)          1
dodge d200                         1
dodge dart custom                  1
dodge monaco (sw)                  1
dodge rampage                      1
honda accord                       2
honda accord cvcc                  1
honda accord lx                    1
honda civic                        3
honda civic (auto)                 1
honda civic 1300                   1
honda civic 1500 gl                1
honda civic cvcc                   2
honda prelude                      1
isuzu D-Max                        2
isuzu D-Max V-Cross                1
isuzu MU-X                         1
jaguar xf                          1
jaguar xj                          1
jaguar xk                          1
maxda glc deluxe                   1
maxda rx3                          1
mazda 626                          3
mazda glc                          2
mazda glc 4                        1
mazda glc custom                   1
mazda glc custom l                 1
mazda glc deluxe                   2
mazda rx-4                         2
mazda rx-7 gs                      2
mazda rx2 coupe                    1
mercury cougar                     1
mitsubishi g4                      3
mitsubishi lancer                  1
mitsubishi mirage                  1
mitsubishi mirage g4               3
mitsubishi montero                 1
mitsubishi outlander               3
mitsubishi pajero                  1
nissan clipper                     2
nissan dayz                        1
nissan fuga                        1
nissan gt-r                        1
nissan juke                        1
nissan kicks                       1
nissan latio                       2
nissan leaf                        1
nissan note                        1
nissan nv200                       1
nissan otti                        1
nissan rogue                       2
nissan teana                       1
nissan titan                       1
peugeot 304                        1
peugeot 504                        6
peugeot 504 (sw)                   1
peugeot 505s turbo diesel          1
peugeot 604sl                      2
plymouth cricket                   1
plymouth duster                    1
plymouth fury gran sedan           1
plymouth fury iii                  2
plymouth satellite custom (sw)     1
plymouth valiant                   1
porcshce panamera                  1
porsche boxter                     1
porsche cayenne                    2
porsche macan                      1
renault 12tl                       1
renault 5 gtl                      1
saab 99e                           2
saab 99gle                         2
saab 99le                          2
subaru                             2
subaru baja                        1
subaru brz                         1
subaru dl                          4
subaru r1                          1
subaru r2                          1
subaru trezia                      1
subaru tribeca                     1
toyota carina                      1
toyota celica gt                   1
toyota celica gt liftback          1
toyota corolla                     6
toyota corolla 1200                2
toyota corolla 1600 (sw)           1
toyota corolla liftback            2
toyota corolla tercel              1
toyota corona                      6
toyota corona hardtop              1
toyota corona liftback             1
toyota corona mark ii              1
toyota cressida                    1
toyota mark ii                     3
toyota starlet                     2
toyota tercel                      1
toyouta tercel                     1
vokswagen rabbit                   1
volkswagen 1131 deluxe sedan       1
volkswagen 411 (sw)                1
volkswagen dasher                  2
volkswagen model 111               1
volkswagen rabbit                  1
volkswagen rabbit custom           1
volkswagen super beetle            1
volkswagen type 3                  1
volvo 144ea                        2
volvo 145e (sw)                    2
volvo 244dl                        2
volvo 245                          1
volvo 246                          1
volvo 264gl                        2
volvo diesel                       1
vw dasher                          1
vw rabbit                          1
Name: CarName, dtype: int64
In [36]:
cars['CarName'].unique()
Out[36]:
array(['alfa-romero giulia', 'alfa-romero stelvio',
       'alfa-romero Quadrifoglio', 'audi 100 ls', 'audi 100ls',
       'audi fox', 'audi 5000', 'audi 4000', 'audi 5000s (diesel)',
       'bmw 320i', 'bmw x1', 'bmw x3', 'bmw z4', 'bmw x4', 'bmw x5',
       'chevrolet impala', 'chevrolet monte carlo', 'chevrolet vega 2300',
       'dodge rampage', 'dodge challenger se', 'dodge d200',
       'dodge monaco (sw)', 'dodge colt hardtop', 'dodge colt (sw)',
       'dodge coronet custom', 'dodge dart custom',
       'dodge coronet custom (sw)', 'honda civic', 'honda civic cvcc',
       'honda accord cvcc', 'honda accord lx', 'honda civic 1500 gl',
       'honda accord', 'honda civic 1300', 'honda prelude',
       'honda civic (auto)', 'isuzu MU-X', 'isuzu D-Max ',
       'isuzu D-Max V-Cross', 'jaguar xj', 'jaguar xf', 'jaguar xk',
       'maxda rx3', 'maxda glc deluxe', 'mazda rx2 coupe', 'mazda rx-4',
       'mazda glc deluxe', 'mazda 626', 'mazda glc', 'mazda rx-7 gs',
       'mazda glc 4', 'mazda glc custom l', 'mazda glc custom',
       'buick electra 225 custom', 'buick century luxus (sw)',
       'buick century', 'buick skyhawk', 'buick opel isuzu deluxe',
       'buick skylark', 'buick century special',
       'buick regal sport coupe (turbo)', 'mercury cougar',
       'mitsubishi mirage', 'mitsubishi lancer', 'mitsubishi outlander',
       'mitsubishi g4', 'mitsubishi mirage g4', 'mitsubishi montero',
       'mitsubishi pajero', 'Nissan versa', 'nissan gt-r', 'nissan rogue',
       'nissan latio', 'nissan titan', 'nissan leaf', 'nissan juke',
       'nissan note', 'nissan clipper', 'nissan nv200', 'nissan dayz',
       'nissan fuga', 'nissan otti', 'nissan teana', 'nissan kicks',
       'peugeot 504', 'peugeot 304', 'peugeot 504 (sw)', 'peugeot 604sl',
       'peugeot 505s turbo diesel', 'plymouth fury iii',
       'plymouth cricket', 'plymouth satellite custom (sw)',
       'plymouth fury gran sedan', 'plymouth valiant', 'plymouth duster',
       'porsche macan', 'porcshce panamera', 'porsche cayenne',
       'porsche boxter', 'renault 12tl', 'renault 5 gtl', 'saab 99e',
       'saab 99le', 'saab 99gle', 'subaru', 'subaru dl', 'subaru brz',
       'subaru baja', 'subaru r1', 'subaru r2', 'subaru trezia',
       'subaru tribeca', 'toyota corona mark ii', 'toyota corona',
       'toyota corolla 1200', 'toyota corona hardtop',
       'toyota corolla 1600 (sw)', 'toyota carina', 'toyota mark ii',
       'toyota corolla', 'toyota corolla liftback',
       'toyota celica gt liftback', 'toyota corolla tercel',
       'toyota corona liftback', 'toyota starlet', 'toyota tercel',
       'toyota cressida', 'toyota celica gt', 'toyouta tercel',
       'vokswagen rabbit', 'volkswagen 1131 deluxe sedan',
       'volkswagen model 111', 'volkswagen type 3', 'volkswagen 411 (sw)',
       'volkswagen super beetle', 'volkswagen dasher', 'vw dasher',
       'vw rabbit', 'volkswagen rabbit', 'volkswagen rabbit custom',
       'volvo 145e (sw)', 'volvo 144ea', 'volvo 244dl', 'volvo 245',
       'volvo 264gl', 'volvo diesel', 'volvo 246'], dtype=object)
In [37]:
cars["CarName"] = np.where(cars["CarName"] == "vw dasher", "volkswagen dasher", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "vw rabbit", "volkswagen rabbit", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "vokswagen rabbit", "volkswagen rabbit", cars["CarName"])

cars["CarName"] = np.where(cars["CarName"] == "toyouta tercel", "toyota tercel", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "toyota corona", "toyota corolla", cars["CarName"])

cars["CarName"] = np.where(cars["CarName"] == "toyota corona hardtop", "toyota corolla hardtop", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "toyota corona liftback", "toyota corolla liftback", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "toyota corona mark ii", "toyota corolla mark ii", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "maxda glc deluxe", "mazda glc deluxe", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "maxda rx3", "mazda rx3", cars["CarName"])

cars["CarName"] = np.where(cars["CarName"] == "audi 100 ls", "audi 100ls", cars["CarName"])
cars["CarName"] = np.where(cars["CarName"] == "porcshce panamera", "porsche panamera", cars["CarName"])
In [38]:
CompanyName = cars['CarName'].apply(lambda x : x.split(' ')[0])

cars.insert(3,"CompanyName",CompanyName)
In [39]:
cars.drop(['car_ID'],axis=1,inplace=True)
In [40]:
cars
Out[40]:
symboling CarName CompanyName fueltype aspiration doornumber carbody drivewheel enginelocation wheelbase carlength carwidth carheight curbweight enginetype cylindernumber enginesize fuelsystem boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price
0 3 alfa-romero giulia alfa-romero gas std two convertible rwd front 88.6 168.8 64.1 48.8 2548 dohc four 130 mpfi 3.47 2.680 9.00 111 5000 21 27 13495.000
1 3 alfa-romero stelvio alfa-romero gas std two convertible rwd front 88.6 168.8 64.1 48.8 2548 dohc four 130 mpfi 3.47 2.680 9.00 111 5000 21 27 16500.000
2 1 alfa-romero Quadrifoglio alfa-romero gas std two hatchback rwd front 94.5 171.2 65.5 52.4 2823 ohcv six 152 mpfi 2.68 3.470 9.00 154 5000 19 26 16500.000
3 2 audi 100ls audi gas std four sedan fwd front 99.8 176.6 66.2 54.3 2337 ohc four 109 mpfi 3.19 3.400 10.00 102 5500 24 30 13950.000
4 2 audi 100ls audi gas std four sedan 4wd front 99.4 176.6 66.4 54.3 2824 ohc five 136 mpfi 3.19 3.400 8.00 115 5500 18 22 17450.000
5 2 audi fox audi gas std two sedan fwd front 99.8 177.3 66.3 53.1 2507 ohc five 136 mpfi 3.19 3.400 8.50 110 5500 19 25 15250.000
6 1 audi 100ls audi gas std four sedan fwd front 105.8 192.7 71.4 55.7 2844 ohc five 136 mpfi 3.19 3.400 8.50 110 5500 19 25 17710.000
7 1 audi 5000 audi gas std four wagon fwd front 105.8 192.7 71.4 55.7 2954 ohc five 136 mpfi 3.19 3.400 8.50 110 5500 19 25 18920.000
8 1 audi 4000 audi gas turbo four sedan fwd front 105.8 192.7 71.4 55.9 3086 ohc five 131 mpfi 3.13 3.400 8.30 140 5500 17 20 23875.000
9 0 audi 5000s (diesel) audi gas turbo two hatchback 4wd front 99.5 178.2 67.9 52.0 3053 ohc five 131 mpfi 3.13 3.400 7.00 160 5500 16 22 17859.167
10 2 bmw 320i bmw gas std two sedan rwd front 101.2 176.8 64.8 54.3 2395 ohc four 108 mpfi 3.50 2.800 8.80 101 5800 23 29 16430.000
11 0 bmw 320i bmw gas std four sedan rwd front 101.2 176.8 64.8 54.3 2395 ohc four 108 mpfi 3.50 2.800 8.80 101 5800 23 29 16925.000
12 0 bmw x1 bmw gas std two sedan rwd front 101.2 176.8 64.8 54.3 2710 ohc six 164 mpfi 3.31 3.190 9.00 121 4250 21 28 20970.000
13 0 bmw x3 bmw gas std four sedan rwd front 101.2 176.8 64.8 54.3 2765 ohc six 164 mpfi 3.31 3.190 9.00 121 4250 21 28 21105.000
14 1 bmw z4 bmw gas std four sedan rwd front 103.5 189.0 66.9 55.7 3055 ohc six 164 mpfi 3.31 3.190 9.00 121 4250 20 25 24565.000
15 0 bmw x4 bmw gas std four sedan rwd front 103.5 189.0 66.9 55.7 3230 ohc six 209 mpfi 3.62 3.390 8.00 182 5400 16 22 30760.000
16 0 bmw x5 bmw gas std two sedan rwd front 103.5 193.8 67.9 53.7 3380 ohc six 209 mpfi 3.62 3.390 8.00 182 5400 16 22 41315.000
17 0 bmw x3 bmw gas std four sedan rwd front 110.0 197.0 70.9 56.3 3505 ohc six 209 mpfi 3.62 3.390 8.00 182 5400 15 20 36880.000
18 2 chevrolet impala chevrolet gas std two hatchback fwd front 88.4 141.1 60.3 53.2 1488 l three 61 2bbl 2.91 3.030 9.50 48 5100 47 53 5151.000
19 1 chevrolet monte carlo chevrolet gas std two hatchback fwd front 94.5 155.9 63.6 52.0 1874 ohc four 90 2bbl 3.03 3.110 9.60 70 5400 38 43 6295.000
20 0 chevrolet vega 2300 chevrolet gas std four sedan fwd front 94.5 158.8 63.6 52.0 1909 ohc four 90 2bbl 3.03 3.110 9.60 70 5400 38 43 6575.000
21 1 dodge rampage dodge gas std two hatchback fwd front 93.7 157.3 63.8 50.8 1876 ohc four 90 2bbl 2.97 3.230 9.41 68 5500 37 41 5572.000
22 1 dodge challenger se dodge gas std two hatchback fwd front 93.7 157.3 63.8 50.8 1876 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 31 38 6377.000
23 1 dodge d200 dodge gas turbo two hatchback fwd front 93.7 157.3 63.8 50.8 2128 ohc four 98 mpfi 3.03 3.390 7.60 102 5500 24 30 7957.000
24 1 dodge monaco (sw) dodge gas std four hatchback fwd front 93.7 157.3 63.8 50.6 1967 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 31 38 6229.000
25 1 dodge colt hardtop dodge gas std four sedan fwd front 93.7 157.3 63.8 50.6 1989 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 31 38 6692.000
26 1 dodge colt (sw) dodge gas std four sedan fwd front 93.7 157.3 63.8 50.6 1989 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 31 38 7609.000
27 1 dodge coronet custom dodge gas turbo two sedan fwd front 93.7 157.3 63.8 50.6 2191 ohc four 98 mpfi 3.03 3.390 7.60 102 5500 24 30 8558.000
28 -1 dodge dart custom dodge gas std four wagon fwd front 103.3 174.6 64.6 59.8 2535 ohc four 122 2bbl 3.34 3.460 8.50 88 5000 24 30 8921.000
29 3 dodge coronet custom (sw) dodge gas turbo two hatchback fwd front 95.9 173.2 66.3 50.2 2811 ohc four 156 mfi 3.60 3.900 7.00 145 5000 19 24 12964.000
30 2 honda civic honda gas std two hatchback fwd front 86.6 144.6 63.9 50.8 1713 ohc four 92 1bbl 2.91 3.410 9.60 58 4800 49 54 6479.000
31 2 honda civic cvcc honda gas std two hatchback fwd front 86.6 144.6 63.9 50.8 1819 ohc four 92 1bbl 2.91 3.410 9.20 76 6000 31 38 6855.000
32 1 honda civic honda gas std two hatchback fwd front 93.7 150.0 64.0 52.6 1837 ohc four 79 1bbl 2.91 3.070 10.10 60 5500 38 42 5399.000
33 1 honda accord cvcc honda gas std two hatchback fwd front 93.7 150.0 64.0 52.6 1940 ohc four 92 1bbl 2.91 3.410 9.20 76 6000 30 34 6529.000
34 1 honda civic cvcc honda gas std two hatchback fwd front 93.7 150.0 64.0 52.6 1956 ohc four 92 1bbl 2.91 3.410 9.20 76 6000 30 34 7129.000
35 0 honda accord lx honda gas std four sedan fwd front 96.5 163.4 64.0 54.5 2010 ohc four 92 1bbl 2.91 3.410 9.20 76 6000 30 34 7295.000
36 0 honda civic 1500 gl honda gas std four wagon fwd front 96.5 157.1 63.9 58.3 2024 ohc four 92 1bbl 2.92 3.410 9.20 76 6000 30 34 7295.000
37 0 honda accord honda gas std two hatchback fwd front 96.5 167.5 65.2 53.3 2236 ohc four 110 1bbl 3.15 3.580 9.00 86 5800 27 33 7895.000
38 0 honda civic 1300 honda gas std two hatchback fwd front 96.5 167.5 65.2 53.3 2289 ohc four 110 1bbl 3.15 3.580 9.00 86 5800 27 33 9095.000
39 0 honda prelude honda gas std four sedan fwd front 96.5 175.4 65.2 54.1 2304 ohc four 110 1bbl 3.15 3.580 9.00 86 5800 27 33 8845.000
40 0 honda accord honda gas std four sedan fwd front 96.5 175.4 62.5 54.1 2372 ohc four 110 1bbl 3.15 3.580 9.00 86 5800 27 33 10295.000
41 0 honda civic honda gas std four sedan fwd front 96.5 175.4 65.2 54.1 2465 ohc four 110 mpfi 3.15 3.580 9.00 101 5800 24 28 12945.000
42 1 honda civic (auto) honda gas std two sedan fwd front 96.5 169.1 66.0 51.0 2293 ohc four 110 2bbl 3.15 3.580 9.10 100 5500 25 31 10345.000
43 0 isuzu MU-X isuzu gas std four sedan rwd front 94.3 170.7 61.8 53.5 2337 ohc four 111 2bbl 3.31 3.230 8.50 78 4800 24 29 6785.000
44 1 isuzu D-Max isuzu gas std two sedan fwd front 94.5 155.9 63.6 52.0 1874 ohc four 90 2bbl 3.03 3.110 9.60 70 5400 38 43 8916.500
45 0 isuzu D-Max V-Cross isuzu gas std four sedan fwd front 94.5 155.9 63.6 52.0 1909 ohc four 90 2bbl 3.03 3.110 9.60 70 5400 38 43 8916.500
46 2 isuzu D-Max isuzu gas std two hatchback rwd front 96.0 172.6 65.2 51.4 2734 ohc four 119 spfi 3.43 3.230 9.20 90 5000 24 29 11048.000
47 0 jaguar xj jaguar gas std four sedan rwd front 113.0 199.6 69.6 52.8 4066 dohc six 258 mpfi 3.63 4.170 8.10 176 4750 15 19 32250.000
48 0 jaguar xf jaguar gas std four sedan rwd front 113.0 199.6 69.6 52.8 4066 dohc six 258 mpfi 3.63 4.170 8.10 176 4750 15 19 35550.000
49 0 jaguar xk jaguar gas std two sedan rwd front 102.0 191.7 70.6 47.8 3950 ohcv twelve 326 mpfi 3.54 2.760 11.50 262 5000 13 17 36000.000
50 1 mazda rx3 mazda gas std two hatchback fwd front 93.1 159.1 64.2 54.1 1890 ohc four 91 2bbl 3.03 3.150 9.00 68 5000 30 31 5195.000
51 1 mazda glc deluxe mazda gas std two hatchback fwd front 93.1 159.1 64.2 54.1 1900 ohc four 91 2bbl 3.03 3.150 9.00 68 5000 31 38 6095.000
52 1 mazda rx2 coupe mazda gas std two hatchback fwd front 93.1 159.1 64.2 54.1 1905 ohc four 91 2bbl 3.03 3.150 9.00 68 5000 31 38 6795.000
53 1 mazda rx-4 mazda gas std four sedan fwd front 93.1 166.8 64.2 54.1 1945 ohc four 91 2bbl 3.03 3.150 9.00 68 5000 31 38 6695.000
54 1 mazda glc deluxe mazda gas std four sedan fwd front 93.1 166.8 64.2 54.1 1950 ohc four 91 2bbl 3.08 3.150 9.00 68 5000 31 38 7395.000
55 3 mazda 626 mazda gas std two hatchback rwd front 95.3 169.0 65.7 49.6 2380 rotor two 70 4bbl 3.33 3.255 9.40 101 6000 17 23 10945.000
56 3 mazda glc mazda gas std two hatchback rwd front 95.3 169.0 65.7 49.6 2380 rotor two 70 4bbl 3.33 3.255 9.40 101 6000 17 23 11845.000
57 3 mazda rx-7 gs mazda gas std two hatchback rwd front 95.3 169.0 65.7 49.6 2385 rotor two 70 4bbl 3.33 3.255 9.40 101 6000 17 23 13645.000
58 3 mazda glc 4 mazda gas std two hatchback rwd front 95.3 169.0 65.7 49.6 2500 rotor two 80 mpfi 3.33 3.255 9.40 135 6000 16 23 15645.000
59 1 mazda 626 mazda gas std two hatchback fwd front 98.8 177.8 66.5 53.7 2385 ohc four 122 2bbl 3.39 3.390 8.60 84 4800 26 32 8845.000
60 0 mazda glc custom l mazda gas std four sedan fwd front 98.8 177.8 66.5 55.5 2410 ohc four 122 2bbl 3.39 3.390 8.60 84 4800 26 32 8495.000
61 1 mazda glc custom mazda gas std two hatchback fwd front 98.8 177.8 66.5 53.7 2385 ohc four 122 2bbl 3.39 3.390 8.60 84 4800 26 32 10595.000
62 0 mazda rx-4 mazda gas std four sedan fwd front 98.8 177.8 66.5 55.5 2410 ohc four 122 2bbl 3.39 3.390 8.60 84 4800 26 32 10245.000
63 0 mazda glc deluxe mazda diesel std four sedan fwd front 98.8 177.8 66.5 55.5 2443 ohc four 122 idi 3.39 3.390 22.70 64 4650 36 42 10795.000
64 0 mazda 626 mazda gas std four hatchback fwd front 98.8 177.8 66.5 55.5 2425 ohc four 122 2bbl 3.39 3.390 8.60 84 4800 26 32 11245.000
65 0 mazda glc mazda gas std four sedan rwd front 104.9 175.0 66.1 54.4 2670 ohc four 140 mpfi 3.76 3.160 8.00 120 5000 19 27 18280.000
66 0 mazda rx-7 gs mazda diesel std four sedan rwd front 104.9 175.0 66.1 54.4 2700 ohc four 134 idi 3.43 3.640 22.00 72 4200 31 39 18344.000
67 -1 buick electra 225 custom buick diesel turbo four sedan rwd front 110.0 190.9 70.3 56.5 3515 ohc five 183 idi 3.58 3.640 21.50 123 4350 22 25 25552.000
68 -1 buick century luxus (sw) buick diesel turbo four wagon rwd front 110.0 190.9 70.3 58.7 3750 ohc five 183 idi 3.58 3.640 21.50 123 4350 22 25 28248.000
69 0 buick century buick diesel turbo two hardtop rwd front 106.7 187.5 70.3 54.9 3495 ohc five 183 idi 3.58 3.640 21.50 123 4350 22 25 28176.000
70 -1 buick skyhawk buick diesel turbo four sedan rwd front 115.6 202.6 71.7 56.3 3770 ohc five 183 idi 3.58 3.640 21.50 123 4350 22 25 31600.000
71 -1 buick opel isuzu deluxe buick gas std four sedan rwd front 115.6 202.6 71.7 56.5 3740 ohcv eight 234 mpfi 3.46 3.100 8.30 155 4750 16 18 34184.000
72 3 buick skylark buick gas std two convertible rwd front 96.6 180.3 70.5 50.8 3685 ohcv eight 234 mpfi 3.46 3.100 8.30 155 4750 16 18 35056.000
73 0 buick century special buick gas std four sedan rwd front 120.9 208.1 71.7 56.7 3900 ohcv eight 308 mpfi 3.80 3.350 8.00 184 4500 14 16 40960.000
74 1 buick regal sport coupe (turbo) buick gas std two hardtop rwd front 112.0 199.2 72.0 55.4 3715 ohcv eight 304 mpfi 3.80 3.350 8.00 184 4500 14 16 45400.000
75 1 mercury cougar mercury gas turbo two hatchback rwd front 102.7 178.4 68.0 54.8 2910 ohc four 140 mpfi 3.78 3.120 8.00 175 5000 19 24 16503.000
76 2 mitsubishi mirage mitsubishi gas std two hatchback fwd front 93.7 157.3 64.4 50.8 1918 ohc four 92 2bbl 2.97 3.230 9.40 68 5500 37 41 5389.000
77 2 mitsubishi lancer mitsubishi gas std two hatchback fwd front 93.7 157.3 64.4 50.8 1944 ohc four 92 2bbl 2.97 3.230 9.40 68 5500 31 38 6189.000
78 2 mitsubishi outlander mitsubishi gas std two hatchback fwd front 93.7 157.3 64.4 50.8 2004 ohc four 92 2bbl 2.97 3.230 9.40 68 5500 31 38 6669.000
79 1 mitsubishi g4 mitsubishi gas turbo two hatchback fwd front 93.0 157.3 63.8 50.8 2145 ohc four 98 spdi 3.03 3.390 7.60 102 5500 24 30 7689.000
80 3 mitsubishi mirage g4 mitsubishi gas turbo two hatchback fwd front 96.3 173.0 65.4 49.4 2370 ohc four 110 spdi 3.17 3.460 7.50 116 5500 23 30 9959.000
81 3 mitsubishi g4 mitsubishi gas std two hatchback fwd front 96.3 173.0 65.4 49.4 2328 ohc four 122 2bbl 3.35 3.460 8.50 88 5000 25 32 8499.000
82 3 mitsubishi outlander mitsubishi gas turbo two hatchback fwd front 95.9 173.2 66.3 50.2 2833 ohc four 156 spdi 3.58 3.860 7.00 145 5000 19 24 12629.000
83 3 mitsubishi g4 mitsubishi gas turbo two hatchback fwd front 95.9 173.2 66.3 50.2 2921 ohc four 156 spdi 3.59 3.860 7.00 145 5000 19 24 14869.000
84 3 mitsubishi mirage g4 mitsubishi gas turbo two hatchback fwd front 95.9 173.2 66.3 50.2 2926 ohc four 156 spdi 3.59 3.860 7.00 145 5000 19 24 14489.000
85 1 mitsubishi montero mitsubishi gas std four sedan fwd front 96.3 172.4 65.4 51.6 2365 ohc four 122 2bbl 3.35 3.460 8.50 88 5000 25 32 6989.000
86 1 mitsubishi pajero mitsubishi gas std four sedan fwd front 96.3 172.4 65.4 51.6 2405 ohc four 122 2bbl 3.35 3.460 8.50 88 5000 25 32 8189.000
87 1 mitsubishi outlander mitsubishi gas turbo four sedan fwd front 96.3 172.4 65.4 51.6 2403 ohc four 110 spdi 3.17 3.460 7.50 116 5500 23 30 9279.000
88 -1 mitsubishi mirage g4 mitsubishi gas std four sedan fwd front 96.3 172.4 65.4 51.6 2403 ohc four 110 spdi 3.17 3.460 7.50 116 5500 23 30 9279.000
89 1 Nissan versa Nissan gas std two sedan fwd front 94.5 165.3 63.8 54.5 1889 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 5499.000
90 1 nissan gt-r nissan diesel std two sedan fwd front 94.5 165.3 63.8 54.5 2017 ohc four 103 idi 2.99 3.470 21.90 55 4800 45 50 7099.000
91 1 nissan rogue nissan gas std two sedan fwd front 94.5 165.3 63.8 54.5 1918 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 6649.000
92 1 nissan latio nissan gas std four sedan fwd front 94.5 165.3 63.8 54.5 1938 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 6849.000
93 1 nissan titan nissan gas std four wagon fwd front 94.5 170.2 63.8 53.5 2024 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 7349.000
94 1 nissan leaf nissan gas std two sedan fwd front 94.5 165.3 63.8 54.5 1951 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 7299.000
95 1 nissan juke nissan gas std two hatchback fwd front 94.5 165.6 63.8 53.3 2028 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 7799.000
96 1 nissan latio nissan gas std four sedan fwd front 94.5 165.3 63.8 54.5 1971 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 7499.000
97 1 nissan note nissan gas std four wagon fwd front 94.5 170.2 63.8 53.5 2037 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 7999.000
98 2 nissan clipper nissan gas std two hardtop fwd front 95.1 162.4 63.8 53.3 2008 ohc four 97 2bbl 3.15 3.290 9.40 69 5200 31 37 8249.000
99 0 nissan rogue nissan gas std four hatchback fwd front 97.2 173.4 65.2 54.7 2324 ohc four 120 2bbl 3.33 3.470 8.50 97 5200 27 34 8949.000
100 0 nissan nv200 nissan gas std four sedan fwd front 97.2 173.4 65.2 54.7 2302 ohc four 120 2bbl 3.33 3.470 8.50 97 5200 27 34 9549.000
101 0 nissan dayz nissan gas std four sedan fwd front 100.4 181.7 66.5 55.1 3095 ohcv six 181 mpfi 3.43 3.270 9.00 152 5200 17 22 13499.000
102 0 nissan fuga nissan gas std four wagon fwd front 100.4 184.6 66.5 56.1 3296 ohcv six 181 mpfi 3.43 3.270 9.00 152 5200 17 22 14399.000
103 0 nissan otti nissan gas std four sedan fwd front 100.4 184.6 66.5 55.1 3060 ohcv six 181 mpfi 3.43 3.270 9.00 152 5200 19 25 13499.000
104 3 nissan teana nissan gas std two hatchback rwd front 91.3 170.7 67.9 49.7 3071 ohcv six 181 mpfi 3.43 3.270 9.00 160 5200 19 25 17199.000
105 3 nissan kicks nissan gas turbo two hatchback rwd front 91.3 170.7 67.9 49.7 3139 ohcv six 181 mpfi 3.43 3.270 7.80 200 5200 17 23 19699.000
106 1 nissan clipper nissan gas std two hatchback rwd front 99.2 178.5 67.9 49.7 3139 ohcv six 181 mpfi 3.43 3.270 9.00 160 5200 19 25 18399.000
107 0 peugeot 504 peugeot gas std four sedan rwd front 107.9 186.7 68.4 56.7 3020 l four 120 mpfi 3.46 3.190 8.40 97 5000 19 24 11900.000
108 0 peugeot 304 peugeot diesel turbo four sedan rwd front 107.9 186.7 68.4 56.7 3197 l four 152 idi 3.70 3.520 21.00 95 4150 28 33 13200.000
109 0 peugeot 504 (sw) peugeot gas std four wagon rwd front 114.2 198.9 68.4 58.7 3230 l four 120 mpfi 3.46 3.190 8.40 97 5000 19 24 12440.000
110 0 peugeot 504 peugeot diesel turbo four wagon rwd front 114.2 198.9 68.4 58.7 3430 l four 152 idi 3.70 3.520 21.00 95 4150 25 25 13860.000
111 0 peugeot 504 peugeot gas std four sedan rwd front 107.9 186.7 68.4 56.7 3075 l four 120 mpfi 3.46 2.190 8.40 95 5000 19 24 15580.000
112 0 peugeot 604sl peugeot diesel turbo four sedan rwd front 107.9 186.7 68.4 56.7 3252 l four 152 idi 3.70 3.520 21.00 95 4150 28 33 16900.000
113 0 peugeot 504 peugeot gas std four wagon rwd front 114.2 198.9 68.4 56.7 3285 l four 120 mpfi 3.46 2.190 8.40 95 5000 19 24 16695.000
114 0 peugeot 505s turbo diesel peugeot diesel turbo four wagon rwd front 114.2 198.9 68.4 58.7 3485 l four 152 idi 3.70 3.520 21.00 95 4150 25 25 17075.000
115 0 peugeot 504 peugeot gas std four sedan rwd front 107.9 186.7 68.4 56.7 3075 l four 120 mpfi 3.46 3.190 8.40 97 5000 19 24 16630.000
116 0 peugeot 504 peugeot diesel turbo four sedan rwd front 107.9 186.7 68.4 56.7 3252 l four 152 idi 3.70 3.520 21.00 95 4150 28 33 17950.000
117 0 peugeot 604sl peugeot gas turbo four sedan rwd front 108.0 186.7 68.3 56.0 3130 l four 134 mpfi 3.61 3.210 7.00 142 5600 18 24 18150.000
118 1 plymouth fury iii plymouth gas std two hatchback fwd front 93.7 157.3 63.8 50.8 1918 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 37 41 5572.000
119 1 plymouth cricket plymouth gas turbo two hatchback fwd front 93.7 157.3 63.8 50.8 2128 ohc four 98 spdi 3.03 3.390 7.60 102 5500 24 30 7957.000
120 1 plymouth fury iii plymouth gas std four hatchback fwd front 93.7 157.3 63.8 50.6 1967 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 31 38 6229.000
121 1 plymouth satellite custom (sw) plymouth gas std four sedan fwd front 93.7 167.3 63.8 50.8 1989 ohc four 90 2bbl 2.97 3.230 9.40 68 5500 31 38 6692.000
122 1 plymouth fury gran sedan plymouth gas std four sedan fwd front 93.7 167.3 63.8 50.8 2191 ohc four 98 2bbl 2.97 3.230 9.40 68 5500 31 38 7609.000
123 -1 plymouth valiant plymouth gas std four wagon fwd front 103.3 174.6 64.6 59.8 2535 ohc four 122 2bbl 3.35 3.460 8.50 88 5000 24 30 8921.000
124 3 plymouth duster plymouth gas turbo two hatchback rwd front 95.9 173.2 66.3 50.2 2818 ohc four 156 spdi 3.59 3.860 7.00 145 5000 19 24 12764.000
125 3 porsche macan porsche gas std two hatchback rwd front 94.5 168.9 68.3 50.2 2778 ohc four 151 mpfi 3.94 3.110 9.50 143 5500 19 27 22018.000
126 3 porsche panamera porsche gas std two hardtop rwd rear 89.5 168.9 65.0 51.6 2756 ohcf six 194 mpfi 3.74 2.900 9.50 207 5900 17 25 32528.000
127 3 porsche cayenne porsche gas std two hardtop rwd rear 89.5 168.9 65.0 51.6 2756 ohcf six 194 mpfi 3.74 2.900 9.50 207 5900 17 25 34028.000
128 3 porsche boxter porsche gas std two convertible rwd rear 89.5 168.9 65.0 51.6 2800 ohcf six 194 mpfi 3.74 2.900 9.50 207 5900 17 25 37028.000
129 1 porsche cayenne porsche gas std two hatchback rwd front 98.4 175.7 72.3 50.5 3366 dohcv eight 203 mpfi 3.94 3.110 10.00 288 5750 17 28 31400.500
130 0 renault 12tl renault gas std four wagon fwd front 96.1 181.5 66.5 55.2 2579 ohc four 132 mpfi 3.46 3.900 8.70 90 5100 23 31 9295.000
131 2 renault 5 gtl renault gas std two hatchback fwd front 96.1 176.8 66.6 50.5 2460 ohc four 132 mpfi 3.46 3.900 8.70 90 5100 23 31 9895.000
132 3 saab 99e saab gas std two hatchback fwd front 99.1 186.6 66.5 56.1 2658 ohc four 121 mpfi 3.54 3.070 9.31 110 5250 21 28 11850.000
133 2 saab 99le saab gas std four sedan fwd front 99.1 186.6 66.5 56.1 2695 ohc four 121 mpfi 3.54 3.070 9.30 110 5250 21 28 12170.000
134 3 saab 99le saab gas std two hatchback fwd front 99.1 186.6 66.5 56.1 2707 ohc four 121 mpfi 2.54 2.070 9.30 110 5250 21 28 15040.000
135 2 saab 99gle saab gas std four sedan fwd front 99.1 186.6 66.5 56.1 2758 ohc four 121 mpfi 3.54 3.070 9.30 110 5250 21 28 15510.000
136 3 saab 99gle saab gas turbo two hatchback fwd front 99.1 186.6 66.5 56.1 2808 dohc four 121 mpfi 3.54 3.070 9.00 160 5500 19 26 18150.000
137 2 saab 99e saab gas turbo four sedan fwd front 99.1 186.6 66.5 56.1 2847 dohc four 121 mpfi 3.54 3.070 9.00 160 5500 19 26 18620.000
138 2 subaru subaru gas std two hatchback fwd front 93.7 156.9 63.4 53.7 2050 ohcf four 97 2bbl 3.62 2.360 9.00 69 4900 31 36 5118.000
139 2 subaru dl subaru gas std two hatchback fwd front 93.7 157.9 63.6 53.7 2120 ohcf four 108 2bbl 3.62 2.640 8.70 73 4400 26 31 7053.000
140 2 subaru dl subaru gas std two hatchback 4wd front 93.3 157.3 63.8 55.7 2240 ohcf four 108 2bbl 3.62 2.640 8.70 73 4400 26 31 7603.000
141 0 subaru subaru gas std four sedan fwd front 97.2 172.0 65.4 52.5 2145 ohcf four 108 2bbl 3.62 2.640 9.50 82 4800 32 37 7126.000
142 0 subaru brz subaru gas std four sedan fwd front 97.2 172.0 65.4 52.5 2190 ohcf four 108 2bbl 3.62 2.640 9.50 82 4400 28 33 7775.000
143 0 subaru baja subaru gas std four sedan fwd front 97.2 172.0 65.4 52.5 2340 ohcf four 108 mpfi 3.62 2.640 9.00 94 5200 26 32 9960.000
144 0 subaru r1 subaru gas std four sedan 4wd front 97.0 172.0 65.4 54.3 2385 ohcf four 108 2bbl 3.62 2.640 9.00 82 4800 24 25 9233.000
145 0 subaru r2 subaru gas turbo four sedan 4wd front 97.0 172.0 65.4 54.3 2510 ohcf four 108 mpfi 3.62 2.640 7.70 111 4800 24 29 11259.000
146 0 subaru trezia subaru gas std four wagon fwd front 97.0 173.5 65.4 53.0 2290 ohcf four 108 2bbl 3.62 2.640 9.00 82 4800 28 32 7463.000
147 0 subaru tribeca subaru gas std four wagon fwd front 97.0 173.5 65.4 53.0 2455 ohcf four 108 mpfi 3.62 2.640 9.00 94 5200 25 31 10198.000
148 0 subaru dl subaru gas std four wagon 4wd front 96.9 173.6 65.4 54.9 2420 ohcf four 108 2bbl 3.62 2.640 9.00 82 4800 23 29 8013.000
149 0 subaru dl subaru gas turbo four wagon 4wd front 96.9 173.6 65.4 54.9 2650 ohcf four 108 mpfi 3.62 2.640 7.70 111 4800 23 23 11694.000
150 1 toyota corolla mark ii toyota gas std two hatchback fwd front 95.7 158.7 63.6 54.5 1985 ohc four 92 2bbl 3.05 3.030 9.00 62 4800 35 39 5348.000
151 1 toyota corolla toyota gas std two hatchback fwd front 95.7 158.7 63.6 54.5 2040 ohc four 92 2bbl 3.05 3.030 9.00 62 4800 31 38 6338.000
152 1 toyota corolla 1200 toyota gas std four hatchback fwd front 95.7 158.7 63.6 54.5 2015 ohc four 92 2bbl 3.05 3.030 9.00 62 4800 31 38 6488.000
153 0 toyota corolla hardtop toyota gas std four wagon fwd front 95.7 169.7 63.6 59.1 2280 ohc four 92 2bbl 3.05 3.030 9.00 62 4800 31 37 6918.000
154 0 toyota corolla 1600 (sw) toyota gas std four wagon 4wd front 95.7 169.7 63.6 59.1 2290 ohc four 92 2bbl 3.05 3.030 9.00 62 4800 27 32 7898.000
155 0 toyota carina toyota gas std four wagon 4wd front 95.7 169.7 63.6 59.1 3110 ohc four 92 2bbl 3.05 3.030 9.00 62 4800 27 32 8778.000
156 0 toyota mark ii toyota gas std four sedan fwd front 95.7 166.3 64.4 53.0 2081 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 30 37 6938.000
157 0 toyota corolla 1200 toyota gas std four hatchback fwd front 95.7 166.3 64.4 52.8 2109 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 30 37 7198.000
158 0 toyota corolla toyota diesel std four sedan fwd front 95.7 166.3 64.4 53.0 2275 ohc four 110 idi 3.27 3.350 22.50 56 4500 34 36 7898.000
159 0 toyota corolla toyota diesel std four hatchback fwd front 95.7 166.3 64.4 52.8 2275 ohc four 110 idi 3.27 3.350 22.50 56 4500 38 47 7788.000
160 0 toyota corolla toyota gas std four sedan fwd front 95.7 166.3 64.4 53.0 2094 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 38 47 7738.000
161 0 toyota corolla toyota gas std four hatchback fwd front 95.7 166.3 64.4 52.8 2122 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 28 34 8358.000
162 0 toyota mark ii toyota gas std four sedan fwd front 95.7 166.3 64.4 52.8 2140 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 28 34 9258.000
163 1 toyota corolla liftback toyota gas std two sedan rwd front 94.5 168.7 64.0 52.6 2169 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 29 34 8058.000
164 1 toyota corolla toyota gas std two hatchback rwd front 94.5 168.7 64.0 52.6 2204 ohc four 98 2bbl 3.19 3.030 9.00 70 4800 29 34 8238.000
165 1 toyota celica gt liftback toyota gas std two sedan rwd front 94.5 168.7 64.0 52.6 2265 dohc four 98 mpfi 3.24 3.080 9.40 112 6600 26 29 9298.000
166 1 toyota corolla tercel toyota gas std two hatchback rwd front 94.5 168.7 64.0 52.6 2300 dohc four 98 mpfi 3.24 3.080 9.40 112 6600 26 29 9538.000
167 2 toyota corolla liftback toyota gas std two hardtop rwd front 98.4 176.2 65.6 52.0 2540 ohc four 146 mpfi 3.62 3.500 9.30 116 4800 24 30 8449.000
168 2 toyota corolla toyota gas std two hardtop rwd front 98.4 176.2 65.6 52.0 2536 ohc four 146 mpfi 3.62 3.500 9.30 116 4800 24 30 9639.000
169 2 toyota starlet toyota gas std two hatchback rwd front 98.4 176.2 65.6 52.0 2551 ohc four 146 mpfi 3.62 3.500 9.30 116 4800 24 30 9989.000
170 2 toyota tercel toyota gas std two hardtop rwd front 98.4 176.2 65.6 52.0 2679 ohc four 146 mpfi 3.62 3.500 9.30 116 4800 24 30 11199.000
171 2 toyota corolla toyota gas std two hatchback rwd front 98.4 176.2 65.6 52.0 2714 ohc four 146 mpfi 3.62 3.500 9.30 116 4800 24 30 11549.000
172 2 toyota cressida toyota gas std two convertible rwd front 98.4 176.2 65.6 53.0 2975 ohc four 146 mpfi 3.62 3.500 9.30 116 4800 24 30 17669.000
173 -1 toyota corolla toyota gas std four sedan fwd front 102.4 175.6 66.5 54.9 2326 ohc four 122 mpfi 3.31 3.540 8.70 92 4200 29 34 8948.000
174 -1 toyota celica gt toyota diesel turbo four sedan fwd front 102.4 175.6 66.5 54.9 2480 ohc four 110 idi 3.27 3.350 22.50 73 4500 30 33 10698.000
175 -1 toyota corolla toyota gas std four hatchback fwd front 102.4 175.6 66.5 53.9 2414 ohc four 122 mpfi 3.31 3.540 8.70 92 4200 27 32 9988.000
176 -1 toyota corolla toyota gas std four sedan fwd front 102.4 175.6 66.5 54.9 2414 ohc four 122 mpfi 3.31 3.540 8.70 92 4200 27 32 10898.000
177 -1 toyota mark ii toyota gas std four hatchback fwd front 102.4 175.6 66.5 53.9 2458 ohc four 122 mpfi 3.31 3.540 8.70 92 4200 27 32 11248.000
178 3 toyota corolla liftback toyota gas std two hatchback rwd front 102.9 183.5 67.7 52.0 2976 dohc six 171 mpfi 3.27 3.350 9.30 161 5200 20 24 16558.000
179 3 toyota corolla toyota gas std two hatchback rwd front 102.9 183.5 67.7 52.0 3016 dohc six 171 mpfi 3.27 3.350 9.30 161 5200 19 24 15998.000
180 -1 toyota starlet toyota gas std four sedan rwd front 104.5 187.8 66.5 54.1 3131 dohc six 171 mpfi 3.27 3.350 9.20 156 5200 20 24 15690.000
181 -1 toyota tercel toyota gas std four wagon rwd front 104.5 187.8 66.5 54.1 3151 dohc six 161 mpfi 3.27 3.350 9.20 156 5200 19 24 15750.000
182 2 volkswagen rabbit volkswagen diesel std two sedan fwd front 97.3 171.7 65.5 55.7 2261 ohc four 97 idi 3.01 3.400 23.00 52 4800 37 46 7775.000
183 2 volkswagen 1131 deluxe sedan volkswagen gas std two sedan fwd front 97.3 171.7 65.5 55.7 2209 ohc four 109 mpfi 3.19 3.400 9.00 85 5250 27 34 7975.000
184 2 volkswagen model 111 volkswagen diesel std four sedan fwd front 97.3 171.7 65.5 55.7 2264 ohc four 97 idi 3.01 3.400 23.00 52 4800 37 46 7995.000
185 2 volkswagen type 3 volkswagen gas std four sedan fwd front 97.3 171.7 65.5 55.7 2212 ohc four 109 mpfi 3.19 3.400 9.00 85 5250 27 34 8195.000
186 2 volkswagen 411 (sw) volkswagen gas std four sedan fwd front 97.3 171.7 65.5 55.7 2275 ohc four 109 mpfi 3.19 3.400 9.00 85 5250 27 34 8495.000
187 2 volkswagen super beetle volkswagen diesel turbo four sedan fwd front 97.3 171.7 65.5 55.7 2319 ohc four 97 idi 3.01 3.400 23.00 68 4500 37 42 9495.000
188 2 volkswagen dasher volkswagen gas std four sedan fwd front 97.3 171.7 65.5 55.7 2300 ohc four 109 mpfi 3.19 3.400 10.00 100 5500 26 32 9995.000
189 3 volkswagen dasher volkswagen gas std two convertible fwd front 94.5 159.3 64.2 55.6 2254 ohc four 109 mpfi 3.19 3.400 8.50 90 5500 24 29 11595.000
190 3 volkswagen rabbit volkswagen gas std two hatchback fwd front 94.5 165.7 64.0 51.4 2221 ohc four 109 mpfi 3.19 3.400 8.50 90 5500 24 29 9980.000
191 0 volkswagen rabbit volkswagen gas std four sedan fwd front 100.4 180.2 66.9 55.1 2661 ohc five 136 mpfi 3.19 3.400 8.50 110 5500 19 24 13295.000
192 0 volkswagen rabbit custom volkswagen diesel turbo four sedan fwd front 100.4 180.2 66.9 55.1 2579 ohc four 97 idi 3.01 3.400 23.00 68 4500 33 38 13845.000
193 0 volkswagen dasher volkswagen gas std four wagon fwd front 100.4 183.1 66.9 55.1 2563 ohc four 109 mpfi 3.19 3.400 9.00 88 5500 25 31 12290.000
194 -2 volvo 145e (sw) volvo gas std four sedan rwd front 104.3 188.8 67.2 56.2 2912 ohc four 141 mpfi 3.78 3.150 9.50 114 5400 23 28 12940.000
195 -1 volvo 144ea volvo gas std four wagon rwd front 104.3 188.8 67.2 57.5 3034 ohc four 141 mpfi 3.78 3.150 9.50 114 5400 23 28 13415.000
196 -2 volvo 244dl volvo gas std four sedan rwd front 104.3 188.8 67.2 56.2 2935 ohc four 141 mpfi 3.78 3.150 9.50 114 5400 24 28 15985.000
197 -1 volvo 245 volvo gas std four wagon rwd front 104.3 188.8 67.2 57.5 3042 ohc four 141 mpfi 3.78 3.150 9.50 114 5400 24 28 16515.000
198 -2 volvo 264gl volvo gas turbo four sedan rwd front 104.3 188.8 67.2 56.2 3045 ohc four 130 mpfi 3.62 3.150 7.50 162 5100 17 22 18420.000
199 -1 volvo diesel volvo gas turbo four wagon rwd front 104.3 188.8 67.2 57.5 3157 ohc four 130 mpfi 3.62 3.150 7.50 162 5100 17 22 18950.000
200 -1 volvo 145e (sw) volvo gas std four sedan rwd front 109.1 188.8 68.9 55.5 2952 ohc four 141 mpfi 3.78 3.150 9.50 114 5400 23 28 16845.000
201 -1 volvo 144ea volvo gas turbo four sedan rwd front 109.1 188.8 68.8 55.5 3049 ohc four 141 mpfi 3.78 3.150 8.70 160 5300 19 25 19045.000
202 -1 volvo 244dl volvo gas std four sedan rwd front 109.1 188.8 68.9 55.5 3012 ohcv six 173 mpfi 3.58 2.870 8.80 134 5500 18 23 21485.000
203 -1 volvo 246 volvo diesel turbo four sedan rwd front 109.1 188.8 68.9 55.5 3217 ohc six 145 idi 3.01 3.400 23.00 106 4800 26 27 22470.000
204 -1 volvo 264gl volvo gas turbo four sedan rwd front 109.1 188.8 68.9 55.5 3062 ohc four 141 mpfi 3.78 3.150 9.50 114 5400 19 25 22625.000
In [41]:
cars['CompanyName'].value_counts()
Out[41]:
toyota         32
mazda          17
nissan         17
mitsubishi     13
honda          13
volkswagen     12
subaru         12
peugeot        11
volvo          11
dodge           9
buick           8
bmw             8
audi            7
plymouth        7
saab            6
porsche         5
isuzu           4
jaguar          3
chevrolet       3
alfa-romero     3
renault         2
mercury         1
Nissan          1
Name: CompanyName, dtype: int64
In [42]:
cars = cars.replace(to_replace ="maxda", value ="mazda") 

Visualizations¶

In [43]:
plt.title('Car Price Spread')
sns.boxplot(y=cars.price)
plt.show()
print(cars.price.describe())
count      205.000000
mean     13276.710571
std       7988.852332
min       5118.000000
25%       7788.000000
50%      10295.000000
75%      16503.000000
max      45400.000000
Name: price, dtype: float64
In [44]:
plt.title('Car Price Distribution Plot')
sns.distplot(cars.price)
plt.show()
In [45]:
plt.figure(figsize=(20,8))

plt.subplot(1,2,1)
plt.title('Car Price Distribution Plot')
sns.distplot(cars.price)

plt.subplot(1,2,2)
plt.title('Car Price Spread')
sns.boxplot(y=cars.price)

plt.show()
print(cars.price.describe())
count      205.000000
mean     13276.710571
std       7988.852332
min       5118.000000
25%       7788.000000
50%      10295.000000
75%      16503.000000
max      45400.000000
Name: price, dtype: float64
In [47]:
company  = cars['CompanyName'].value_counts()
company = company[:10,]
plt.figure(figsize=(10,5))
sns.barplot(company.index, company.values, alpha=0.8)
plt.title('Company')
plt.ylabel('Number of Occurrences', fontsize=12)
plt.xlabel('Company', fontsize=12)
plt.show()
In [48]:
company  = cars['CompanyName'].value_counts()
plt.figure(figsize=(10,5))
sns.barplot(company.index, company.values, alpha=0.8)
plt.title('Company')
plt.ylabel('Number of Occurrences', fontsize=12)
plt.xlabel('Company', fontsize=12)
plt.xticks(rotation = 40)
plt.show()
In [49]:
def plot_count(x,fig):
    plt.subplot(4,2,fig)
    plt.title(x+' Histogram')
    sns.countplot(cars[x],palette=("magma"))
    plt.subplot(4,2,(fig+1))
    plt.title(x+' vs Price')
    sns.boxplot(x=cars[x], y=cars.price, palette=("magma"))
    
plt.figure(figsize=(15,20))

plot_count('enginelocation', 1)
plot_count('cylindernumber', 3)
plot_count('fuelsystem', 5)
plot_count('drivewheel', 7)

plt.tight_layout()
In [50]:
def scatter(x,fig):
    plt.subplot(5,2,fig)
    plt.scatter(cars[x],cars['price'])
    plt.title(x+' vs Price')
    plt.ylabel('Price')
    plt.xlabel(x)

plt.figure(figsize=(10,20))

scatter('carlength', 1)
scatter('carwidth', 2)
scatter('carheight', 3)
scatter('curbweight', 4)

plt.tight_layout()
In [51]:
#Binning the Car Companies based on avg prices of each Company.
cars['price'] = cars['price'].astype('int')
bins = [0,10000,20000,40000]
cars_bin=['Budget','Medium','Highend']
cars['carsrange_binned'] = pd.cut(cars['price'],bins,right=False,labels=cars_bin)
cars.head()
Out[51]:
symboling CarName CompanyName fueltype aspiration doornumber carbody drivewheel enginelocation wheelbase carlength carwidth carheight curbweight enginetype cylindernumber enginesize fuelsystem boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price carsrange_binned
0 3 alfa-romero giulia alfa-romero gas std two convertible rwd front 88.6 168.8 64.1 48.8 2548 dohc four 130 mpfi 3.47 2.68 9.0 111 5000 21 27 13495 Medium
1 3 alfa-romero stelvio alfa-romero gas std two convertible rwd front 88.6 168.8 64.1 48.8 2548 dohc four 130 mpfi 3.47 2.68 9.0 111 5000 21 27 16500 Medium
2 1 alfa-romero Quadrifoglio alfa-romero gas std two hatchback rwd front 94.5 171.2 65.5 52.4 2823 ohcv six 152 mpfi 2.68 3.47 9.0 154 5000 19 26 16500 Medium
3 2 audi 100ls audi gas std four sedan fwd front 99.8 176.6 66.2 54.3 2337 ohc four 109 mpfi 3.19 3.40 10.0 102 5500 24 30 13950 Medium
4 2 audi 100ls audi gas std four sedan 4wd front 99.4 176.6 66.4 54.3 2824 ohc five 136 mpfi 3.19 3.40 8.0 115 5500 18 22 17450 Medium
In [52]:
cars_new = cars[['price', 'fueltype', 'aspiration','carbody', 'drivewheel','wheelbase',
                  'curbweight', 'enginetype', 'cylindernumber', 'enginesize', 'boreratio','horsepower', 
                     'carlength','carwidth', 'carsrange_binned']]
cars_new.head()
sns.pairplot(cars_new)
plt.show()
In [53]:
c = ['#F1C40F', '#3498DB',"#9b59b6"]
labels = ['Budget','Medium','Highend']

patches, texts, pcts=plt.pie(cars['carsrange_binned'].value_counts(),labels =labels,colors=c, autopct='%.1f%%' ,
         wedgeprops={'linewidth': 5.0, 'edgecolor': 'white'},textprops={'size': '15', 'color':'black'})
plt.setp(texts, fontweight=700)

for i, color in enumerate(c):
    texts[i].set_color(color)
In [54]:
plt.figure(figsize=(15,10))
sns.countplot(x='carbody', data = cars,
              order=pd.value_counts(cars['carbody']).index, palette='BuGn_r')
plt.title('Number of Cars grouped by carbody', weight='bold')
plt.xlabel('Type', fontsize=12)
plt.ylabel('Count', fontsize=12)
Out[54]:
Text(0, 0.5, 'Count')
In [55]:
fig, ax1 = plt.subplots(figsize=(20,10))
graph = sns.countplot(ax=ax1,x='carbody', data=cars, order=pd.value_counts(cars['carbody']).index, palette='BuGn_r')
graph.set_xticklabels(graph.get_xticklabels())
i=0
for p in graph.patches:
    height = p.get_height()
    graph.text(p.get_x()+p.get_width()/2., height + 0.1,
        cars['carbody'].value_counts()[i],ha="center")
    i += 1

plt.xlabel('Carbody TYpe', fontsize=12)
plt.ylabel('Count', fontsize=12)
plt.title('Number of Cars grouped by carbody', weight='bold')
Out[55]:
Text(0.5, 1.0, 'Number of Cars grouped by carbody')
In [56]:
cars['carbody'].value_counts()
Out[56]:
sedan          96
hatchback      70
wagon          25
hardtop         8
convertible     6
Name: carbody, dtype: int64
In [57]:
#df['adr'] = df['adr'].astype(float)
from numpy import mean
plt.figure(figsize=(15,10))
sns.barplot(x='carbody', y='citympg', hue='carsrange_binned', dodge=True, palette= 'PuBu_r', data=cars,estimator=mean,ci = None)
plt.title('Price Range grouped by Carbody and Fueltype', weight='bold')
plt.xlabel('Carbody', fontsize=12)
plt.ylabel('citympg', fontsize=12)
Out[57]:
Text(0, 0.5, 'citympg')
In [58]:
from numpy import mean
plt.figure(figsize=(15,10))
sns.barplot(x='carbody', y='price',  palette= 'PuBu_r', data=cars,estimator=mean,ci = None)
plt.title('Price ', weight='bold')
plt.xlabel('Carbody', fontsize=12)
plt.ylabel('price', fontsize=12)
Out[58]:
Text(0, 0.5, 'price')
In [59]:
plt.figure(figsize=(10,8))
sns.countplot(x='carbody',order=pd.value_counts(cars['carbody']).index,hue='fueltype',data=cars)
plt.xticks(rotation = 40)
plt.show()
In [60]:
plt.figure(figsize=(10,6))
sns.kdeplot(cars.citympg, shade=True,color="r")
plt.xlim((0,54))
plt.title("Density plot on City Mileage")
plt.ylabel("Density")
plt.xlabel('City Mileage')
plt.grid(True)
plt.show()
In [61]:
plt.figure(figsize=(10,6))
fig = sns.kdeplot(cars['citympg'], shade=True, color="r")
fig = sns.kdeplot(cars['highwaympg'], shade=True, color="b")
plt.grid(True)
plt.show()
In [62]:
plt.figure(figsize=(15,10))
sns.lineplot(data = cars, x = 'enginesize', y = 'horsepower', hue = 'carsrange_binned')
plt.title("Engine Size and Horsepower by Price Range")
plt.ylabel("Horse Power")
plt.xlabel('Engine Size')
plt.show()
In [63]:
cars.enginesize.hist(bins=10, alpha=0.5)
plt.title(" Histogram")
plt.xlabel("Engine Size")
plt.ylabel("Frequency")
Out[63]:
Text(0, 0.5, 'Frequency')
In [64]:
corrmat=cars.corr()
top_corr_feature=corrmat.index
plt.figure(figsize=(20,20))
g=sns.heatmap(cars[top_corr_feature].corr(), annot=True,cmap="RdYlGn")
In [65]:
num = cars.select_dtypes(exclude = 'object')
numcorr = cars.corr()
f, ax = plt.subplots(figsize = (19,1)) # set figure size
sns.heatmap(numcorr.sort_values(by = 'price', ascending = False).head(1), annot = True, fmt = ".2f")
plt.show()
In [66]:
numcorr['price'].sort_values(ascending = False).to_frame().plot.bar(color = 'blue')
plt.axhline(y = 0.5, color = 'r', linestyle = '-')
plt.title('Corrplot vs. Price')
plt.show()
In [67]:
#cars.to_excel("cars_cleaned.xlsx",sheet_name='Cleaned')

Feature Engineering¶

In [68]:
list5 = []
for index,row in cars.iterrows():
    if len(row.doornumber) > 1:
        list5.append(w2n.word_to_num(row.doornumber))
    else:
        list5.append('4')
In [69]:
cars['doornumber_int'] = pd.Series(list5)
In [70]:
cars['doornumber_int'].unique()
Out[70]:
array([2, 4], dtype=int64)
In [71]:
cars.drop(['doornumber'],axis=1,inplace=True)
In [72]:
list6 = []
for index,row in cars.iterrows():
    if len(row.cylindernumber) > 1:
        list6.append(w2n.word_to_num(row.cylindernumber))
    else:
        list6.append('4')
In [73]:
cars['cylindernumber_int'] = pd.Series(list6)
In [74]:
cars['cylindernumber_int'].unique()
Out[74]:
array([ 4,  6,  5,  3, 12,  2,  8], dtype=int64)
In [75]:
cars.drop(['cylindernumber'],axis=1,inplace=True)

One Hot Encoding¶

In [76]:
#split the dependent variable and independent variable
cars_X =  cars.copy()
cars_X.drop(['price'],axis=1,inplace=True)
cars_y = cars['price']
In [77]:
cars_x= cars_X.iloc[:,:].values
In [78]:
type(cars_x)
Out[78]:
numpy.ndarray
In [79]:
cars.head(1)
Out[79]:
symboling CarName CompanyName fueltype aspiration carbody drivewheel enginelocation wheelbase carlength carwidth carheight curbweight enginetype enginesize fuelsystem boreratio stroke compressionratio horsepower peakrpm citympg highwaympg price carsrange_binned doornumber_int cylindernumber_int
0 3 alfa-romero giulia alfa-romero gas std convertible rwd front 88.6 168.8 64.1 48.8 2548 dohc 130 mpfi 3.47 2.68 9.0 111 5000 21 27 13495 Medium 2 4
In [80]:
list(cars_x[1,:])
Out[80]:
[3,
 'alfa-romero stelvio',
 'alfa-romero',
 'gas',
 'std',
 'convertible',
 'rwd',
 'front',
 88.6,
 168.8,
 64.1,
 48.8,
 2548,
 'dohc',
 130,
 'mpfi',
 3.47,
 2.68,
 9.0,
 111,
 5000,
 21,
 27,
 'Medium',
 2,
 4]
In [81]:
#list all the categorical variables
columns_ohe = [1,2,3,4,5,6,7,13,15,23]
In [84]:
list(cars_x[1,[1,2,3,4,5,6,7,13,15,23]])
Out[84]:
['alfa-romero stelvio',
 'alfa-romero',
 'gas',
 'std',
 'convertible',
 'rwd',
 'front',
 'dohc',
 'mpfi',
 'Medium']
In [82]:
for num in tqdm(columns_ohe):
    dummy_ = pd.get_dummies(cars_x[:,num],sparse=True)
    if(num!=1):
        dummy = np.concatenate((dummy,dummy_),axis=1)
    else:
        dummy = dummy_
100%|█████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 303.84it/s]
In [85]:
list(cars_x[1,:])
Out[85]:
[3,
 'alfa-romero stelvio',
 'alfa-romero',
 'gas',
 'std',
 'convertible',
 'rwd',
 'front',
 88.6,
 168.8,
 64.1,
 48.8,
 2548,
 'dohc',
 130,
 'mpfi',
 3.47,
 2.68,
 9.0,
 111,
 5000,
 21,
 27,
 'Medium',
 2,
 4]
In [86]:
cars_x = np.delete(cars_x,columns_ohe,1)
In [88]:
cars_x = np.concatenate((cars_x,dummy),axis=1)
In [89]:
list(cars_x[1,:])
Out[89]:
[3,
 88.6,
 168.8,
 64.1,
 48.8,
 2548,
 130,
 3.47,
 2.68,
 9.0,
 111,
 5000,
 21,
 27,
 2,
 4,
 0,
 0,
 0,
 1,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 1,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 1,
 1,
 0,
 1,
 0,
 0,
 0,
 0,
 0,
 0,
 1,
 1,
 0,
 1,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 0,
 1,
 0,
 0,
 0,
 0,
 1]

Data Splitting¶

In [90]:
np.random.seed(0)
number_of_samples = len(cars_x)
random_indices = np.random.permutation(number_of_samples)
num_training_samples = int(number_of_samples*0.75)
cars_x_train = cars_x[random_indices[:num_training_samples]]
cars_y_train=cars_y[random_indices[:num_training_samples]]
cars_x_validation=cars_x[random_indices[num_training_samples:]]
cars_y_validation=cars_y[random_indices[num_training_samples:]]
In [91]:
len(cars_x_train)
Out[91]:
153
In [92]:
len(cars_y_train)
Out[92]:
153
In [93]:
len(cars_x_validation)
Out[93]:
52
In [94]:
len(cars_y_validation)
Out[94]:
52

Standard Scaling¶

In [95]:
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
# Fit on training set only.
scaler.fit(cars_x_train)
# Apply transform to both thvfe training set and the test set.
cars_x_train = scaler.transform(cars_x_train)
cars_x_validation = scaler.transform(cars_x_validation)
In [96]:
cars_x_train.shape
Out[96]:
(153, 210)
In [97]:
cars_x_validation.shape
Out[97]:
(52, 210)

Principal Component Analysis¶

In [98]:
from sklearn.decomposition import PCA
# Make an instance of the Model
pca = PCA(.95)
pca.fit(cars_x_train)
cars_x_train = pca.transform(cars_x_train)
cars_x_validation = pca.transform(cars_x_validation)
In [99]:
cars_x_train.shape
Out[99]:
(153, 107)
In [100]:
cars_x_validation.shape
Out[100]:
(52, 107)

Linear Regression¶

In [ ]:
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(cars_x_train, cars_y_train)
cars_linear_train_predicted = model.predict(cars_x_train)
cars_linear_validation_predicted = model.predict(cars_x_validation)
In [ ]:
from sklearn.metrics import r2_score,mean_squared_error
r2_score(cars_y_train, cars_linear_train_predicted)
In [ ]:
r2_score(cars_y_validation, cars_linear_validation_predicted)
In [ ]:
# The coefficients
#print("Coefficients: \n", model.coef_)
# The mean squared error
print("Training data -Mean squared error: %.2f" % mean_squared_error(cars_y_train, cars_linear_train_predicted))
print("Validation data - Mean squared error: %.2f" % mean_squared_error(cars_y_validation, cars_linear_validation_predicted))
# The coefficient of determination: 1 is perfect prediction
print("Training data Coefficient of determination: %.2f" % r2_score(cars_y_train, cars_linear_train_predicted))
print("Validation data Coefficient of determination: %.2f" % r2_score(cars_y_validation, cars_linear_validation_predicted))

# Plot outputs
plt.scatter(cars_y_train, cars_linear_train_predicted, color="black")
plt.scatter(cars_y_validation, cars_linear_validation_predicted, color="red")

#plt.plot(cars_y_validation, cars_linear_validation_predicted, color="blue", linewidth=3)

plt.xticks(())
plt.yticks(())
plt.title(" Dot Chart")
plt.xlabel("Actual Data")
plt.ylabel("Predicted Data")

plt.show()
In [ ]: